#!/bin/bash
yum install httpd apr apr-util httpd-devel subversion mod_dav_svn mod_auth_mysql -y
chkconfig httpd on
service httpd on
mkdir -p /home/svn
cd /home/svn
svnadmin create /home/svn/project1
svnadmin create /home/svn/project2
svnadmin create /home/svn/project3
mkdir -p /home/svn/conf
cp /home/svn/project1/conf/passwd /home/svn/conf/passwd
cp /home/svn/project1/conf/authz /home/svn/conf/authz
cp /home/svn/project1/conf/passwd /home/svn/conf/svnserve.conf 
echo "svnuser = svnuser">>/home/svn/conf/passwd
echo "svnuser1 = svnuser1">>/home/svn/conf/passwd
echo "svnuser2 = svnuser2">>/home/svn/conf/passwd
echo "svnuser3 = svnuser3">>/home/svn/conf/passwd
cat >/home/svn/conf/authz <<EOF
[groups]
svnuser = svnuser
svnuser1 = svnuser1
svnuser2 = svnuser2
svnuser3 = svnuser3
[/]
@svnuser = rw
* =
[project1:/]
@svnuser = rw
@svnuser1 = rw
* =
[project2:/]
@svnuser = rw
@svnuser2 = rw
* =
[project3:/]
@svnuser = rw
@svnuser3 = rw
* =
EOF
cat >>/home/svn/conf/svnserve.conf<<EOF
[general]
anon-access=none
auth-access=write 
password-db=/home/svn/conf/passwd
authz-db=/home/svn/conf/authz
realm=svn
EOF
svnserve -d -r /home/svn --config-file /home/svn/conf/svnserve.conf --listen-port 3690
cat >/etc/init.d/svn <<EOF
vi /etc/init.d/svn #编辑，添加以下代码
#!/bin/sh
# chkconfig: 2345 85 85
# processname: svn
svn_bin=/usr/local/svn/bin
svn_port=3690
svn_home=/home/svn
svn_config=/home/svn/conf/svnserve.conf
if [ ! -f "$svn_bin/svnserve" ]
then
echo "svnserver startup: cannot start"
exit
fi
case "$1" in
start)
echo "Starting svnserve..."
$svn_bin/svnserve -d -r $svn_home --config-file $svn_config --listen-port $svn_port
echo "Successfully!"
;;
stop)
echo "Stoping svnserve..."
killall svnserve
echo "Successfully!"
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: svn { start | stop | restart } "
exit 1
esac
EOF
